package com.taldh;

import org.junit.Assert;
import org.junit.Test;

public class TwoNumberSumSortInput {

    @Test
    public void twoSumTest() {
        int[] ints = twoSum(new int[]{2, 7, 11, 15}, 9);
        Assert.assertEquals(2, ints.length);
        Assert.assertEquals(1, ints[0]);
        Assert.assertEquals(2, ints[1]);
    }

    public int[] twoSum(int[] numbers, int target) {
        int i = 0, j = numbers.length - 1;
        while (i < j) {
            int sum = numbers[i] + numbers[j];
            if (sum == target) {
                return new int[]{i + 1, j + 1};
            } else if (sum < target) {
                i++;
            } else {
                j--;
            }
        }
        return null;
    }

}
